#ifndef __STREAMSOCKET_H__
#define __STREAMSOCKET_H__

#include <iostream>
#include <stdio.h>
#include <ostream>

#include <boost/thread.hpp>
#include <boost/bind.hpp>
#include <boost/array.hpp>
#include <boost/asio.hpp>

/// TEMPORAL ///
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/xml_parser.hpp>

using namespace std;

using boost::asio::ip::tcp;
using boost::property_tree::ptree;

class StreamSocket {
	
public:
	StreamSocket( boost::asio::io_service& ios ) : Socket( ios ), Resolver( ios ) {}
	virtual ~StreamSocket() {}
	
	void Connect( ptree& cfg );
// 	void Write();
// 	void Close();
	
	virtual void OnConnect( const boost::system::error_code& error )  { printf("VIRTUAL %d:%s\n", error.value(), error.message().c_str()); }
	virtual void OnReceive( const boost::system::error_code& error ) { printf("RECV[%d] : %d [%s]\n", error.value(), Buffer.size(), Buffer.data()); }
	
// 	void DoClose();
    
private:
// 	virtual size_t ReceiveHdlr();
	virtual void ConnectHdlr( const boost::system::error_code& error );
	virtual void ResolveHdlr( const boost::system::error_code& error, tcp::resolver::iterator endp );
	
// 	boost::asio::io_service& xService;
	tcp::socket Socket;
	tcp::resolver Resolver;
	
	boost::array<char,128> Buffer;
// 	size_t m_BufLen;
};


#endif
